import {myFetch} from '@/assets/js/utils.js'

export default{
    // 加入购物车
    async addGoods ({goodsId, goodsNum}) {
        const data = await myFetch({
            name: 'shopping.sys.add.goods',
            user_id: 0,
            goods_id: goodsId,
            goods_num: goodsNum
        })
        return data
    },
    // 获取购物车商品列表
    async getCartGoods () {
        const data = await myFetch({
            name: 'shopping.sys.shop.cart',
            user_id: 0
        })
        return data
    },
    // 获取购物车商品件数
    async getCartNum () {
        const data = await myFetch({
            name: 'shopping.sys.shop.cart.count'
        })
        return data
    },
    // 编辑某商品件数
    async editGoodsNum ({num, goods_id}) {
        const data = await myFetch({
            name: 'shopping.sys.shopcart.num.change',
            user_id: 0,
            goods_id,
            goods_num: num,
            is_selected: 0
        })
        return data.data.store
    },
    // 购物车商品转收藏
    async collectGoods ({preGoodsIdArr, goodsIdArr}) {
        const data = await myFetch({
            name: 'shopping.sys.array.collect',
            user_id: 0,
            for_id: preGoodsIdArr.toString(),
            for_type: 'pre_goods',
            goods_id: goodsIdArr.toString()
        })
        return data
    },
    // 购物车商品移除
    async removeGoods ({goodsIdArr}) {
        const data = await myFetch({
            name: 'shopping.sys.del.goods',
            user_id: 0,
            goods_id: goodsIdArr.toString(),
            is_selected: 1
        })
        return data
    }
}
